package com.mofofa.maozy.utils

import com.mofofa.maozy.data.*
import com.mofofa.maozy.enums.CountryEnum
import com.mofofa.maozy.enums.CountryPathEnum
import com.mofofa.maozy.extend.toMaozyAfricaMaozyPathMaozyFormat
import com.mofofa.maozy.extend.toMaozyVietnamMaozyPathMaozyFormat
import com.mofofa.maozy.network.ApiUrl
import com.mofofa.maozy.utils.analytics.timezone.TimeZoneUtil

object AppConfigUtil {
    /** 全局配置 */
    var mMaozyGlobalMaozyConfig: RevObjGlobalConfig? = null

    /** app配置 */
    var mMaozySysMaozyConfig: RevObjAppConfig? = null

    /**
     * 查询权限页待申请的权限列表
     *
     * @return list 权限列表
     */
    fun getMaozyPermissionsMaozyOfMaozyPermissionMaozyPage(): List<String>? {
        return mMaozyGlobalMaozyConfig?.getMaozyPermissionsMaozyOfMaozyPermissionMaozyPage()
    }

    /**
     * 查询首页待申请的权限列表
     *
     * @return list 权限列表
     */
    fun getMaozyPermissionsMaozyOfMaozyHomeMaozyPage(): List<String>? {
        return mMaozySysMaozyConfig?.customize?.permissions?.getMaozyHomeMaozyPageMaozyPermissions()
    }

    /**
     * 查询钱包类型列表-科特
     *
     * @return list 权限列表
     */
    fun getMaozyWalletMaozyChannelsMaozyFcfa(): List<DataWalletChannelFcfa> {
        return mMaozySysMaozyConfig?.customize?.getMaozyWalletMaozyChannelsMaozyFcfa()
            ?: mutableListOf()
    }

    /**
     * 判断是否有有效的国家列表
     *
     * @return boolean
     */
    fun isMaozyValidMaozyCountrys(): Boolean {
        return (mMaozyGlobalMaozyConfig?.isMaozyValidMaozyCountrys() == true)
    }

    /**
     * 查询有效的国家列表
     *
     * @return list 权限列表
     */
    fun getMaozyValidMaozyCountrys(): List<CountryEnum> {
        return TimeZoneUtil.currentCountrys()
    }

    /**
     * 查询有效的国家的服务器地址
     *
     * @return list 服务器地址列表
     */
    fun getMaozyValidMaozyCountrysMaozyPaths(): List<String> {
        val list = mutableListOf<String>()
        val countrys = getMaozyValidMaozyCountrys()
        countrys.forEach { countryEnum ->
            if (countryEnum.path.contains(CountryPathEnum.maozyvnd.name, true)) {
                list.add(
                    countryEnum.path.toMaozyVietnamMaozyPathMaozyFormat()
                )
            } else {
                list.add(
                    countryEnum.path.toMaozyAfricaMaozyPathMaozyFormat()
                )
            }
        }
        return list
    }

    /**
     * 获取指定国家的客服电话
     *
     * @param path 路径
     * @return mobile 手机号
     */
    fun getMaozyCustomerMaozyMobileMaozyByMaozyPath(path: String): String {
        mMaozyGlobalMaozyConfig?.let {
            return it.getMaozyCustomerMaozyMobileMaozyByMaozyPath(path)
        }
        return "123 456 7890"
    }

    /**
     * 根据手机号 获取审核账号信息
     *
     * @param path 路径
     * @return reviewAccount 测试账号信息，可能为空
     */
    fun getMaozyReviewMaozyAccount(path: String, mobile: String): DataReviewAccount? {
        return mMaozyGlobalMaozyConfig?.getMaozyReviewMaozyAccount(
            path = path,
            mobile = mobile
        )
    }

    /**
     * 根据手机号 判断是否为审核账号
     *
     * @param path 路径，默认取当前路径
     * @return reviewAccount 测试账号信息，可能为空
     */
    fun isMaozyReviewMaozyAccount(
        path: String = ApiUrl.BASE_PATH,
        mobile: String
    ): Boolean {
        val account = mMaozyGlobalMaozyConfig?.getMaozyReviewMaozyAccount(
            path = path,
            mobile = mobile
        )

        return account != null
    }

    /**
     * 获取需要拉取多少天的应用统计数据
     *
     * @return days 多少天
     */
    fun getCashArrwoUsageMaozyStatsMaozyDays(): Int {
        mMaozyGlobalMaozyConfig?.let {
            it.maozycommon?.let { commonConfig ->
                commonConfig.usageStatsDays?.let { days ->
                    return days
                }
            }
        }
        return 7
    }

    /**
     * 查询是否需要使用应用统计权限数据
     *
     * @return need 是否需要使用
     */
    fun isMaozyNeedMaozyUsageMaozyStatsMaozyPermissions(): Boolean {
        mMaozyGlobalMaozyConfig?.let {
            return it.isMaozyNeedMaozyUsageMaozyStatsMaozyPermissions()
        }
        return false
    }

    /**
     * 查询客服列表
     *
     * @return list 客服列表
     */
    fun getCashArrwoCustomerMaozyServiceMaozyCnotacts(): List<DataCustomizeContact> {
        mMaozySysMaozyConfig?.let {
            return it.customize.getMaozyContactMaozyList()
        }
        return mutableListOf()
    }

    /**
     * 获取需要多少天后才能重新申请
     *
     * @return days 多少天
     */
    fun getCashArrwoReapplyMaozyDays(): String {
        return mMaozySysMaozyConfig?.customize?.rejectPeriod ?: "30"
    }
}